package com.fimmlps.reronge.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fimmlps.reronge.entity.EntryTrigger;
import com.fimmlps.reronge.mapper.EntryTriggerMapper;
import com.fimmlps.reronge.service.IEntryTriggerService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class EntryTriggerServiceImpl extends ServiceImpl<EntryTriggerMapper, EntryTrigger> implements IEntryTriggerService {
    @Override
    public ArrayList<EntryTrigger> getTriggersFromText(ArrayList<String> ts) {
        ArrayList<EntryTrigger> triggers = new ArrayList<>();
        for(String s:ts){
            getTriggerByName(s,triggers);
        }
        return triggers;
    }

    private void getTriggerByName(String name,ArrayList<EntryTrigger> triggers){
        QueryWrapper<EntryTrigger> likes = new QueryWrapper<>();
        likes.eq("enabled",0);
        likes.like("text",name);
        List<EntryTrigger> ets = list(likes);
        triggers.addAll(ets);
    }

    @Override
    public ArrayList<EntryTrigger> getEnabledTriggersBySingleId(int singleId) {
        ArrayList<EntryTrigger> triggers = (ArrayList<EntryTrigger>) baseMapper.selectList(new QueryWrapper<EntryTrigger>().eq("enabled",0).eq("entry_single_id",singleId));
        return triggers;
    }
}
